﻿Public Class LotHierarchieExplorer
    Inherits ExplorerTreeList

    Private EditPanePL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If
        '
        Dim guidEnfant As Guid
        Dim aPLName As String

        Dim aPaneMetaQueryName As String
        Dim Ametaquerie As MetaQuery
        Dim frmCaption As String = Nothing

        Try
            guidEnfant = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
            aPLName = DirectCast(NodeDataRow("PL"), String)

            aPaneMetaQueryName = DirectCast(NodeDataRow("MetaQuerie"), String)
            Ametaquerie = MetaQuery.GetMetaQueryByName(aPaneMetaQueryName)

            'c<est ici qu<on bind les info du noeud qui articule le Edit PANE
            EditPanePL = PLBase.CreateInstanceOf(aPLName, aPaneMetaQueryName)

            aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = EditPanePL, .SecureGrid = True, .Name = Ametaquerie.Caption, .FormCtrlCD = MyBase.PanelName}
            If Not Guid.Empty.Equals(guidEnfant) Then
                EditPanePL.SQLWhere = String.Format("{0} = '{1}'", Ametaquerie.GUIDField, guidEnfant)

            End If

        Catch ex As Exception
            MessageWindow.ShowMessage(ex)

        End Try


        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub

End Class
